package com.lijinjiang.listener;

import com.lijinjiang.component.JDatePanel;
import com.lijinjiang.component.SelectDatePanel;
import com.lijinjiang.constant.Colors;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * @Description 点击顶部标签监听
 * @Author lijinjiang
 * @Date 2024-12-30 10:52
 */
public class ClickTopLabelListener implements MouseListener {
    private final JDatePanel datePanel;

    public ClickTopLabelListener(JDatePanel datePanel) {
        this.datePanel = datePanel;
    }

    @Override public void mouseClicked(MouseEvent e) {
        if (e.getButton() == MouseEvent.BUTTON1) {//左键点击
            Object source = e.getSource();
            SelectDatePanel selectDatePanel = datePanel.getSelectDatePanel();
            if (source == datePanel.getYearLabel()) {//点击年标签
                selectDatePanel.clickYearLabel();
            } else if (source == datePanel.getMonthLabel()) {//点击月标签
                selectDatePanel.clickMonthLabel();
            }
        }
    }

    @Override public void mousePressed(MouseEvent e) {

    }

    @Override public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {
        Object source = e.getSource();
        if (source instanceof JLabel) {
            JLabel label = (JLabel) source;
            label.setForeground(Colors.FG_ENTERED);
        }
    }

    @Override
    public void mouseExited(MouseEvent e) {
        Object source = e.getSource();
        if (source instanceof JLabel) {
            JLabel label = (JLabel) source;
            label.setForeground(Color.BLACK);
        }
    }
}
